package com.suyang.syt.service.impl;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.suyang.syt.dao.interfaces.UserDao;
import com.suyang.syt.model.User;
import com.suyang.syt.model.dto.AjaxObj;
import com.suyang.syt.service.interfaces.LoginService;
import com.suyang.syt.util.Md5Util;

@Service
@Deprecated
public class LoginServiceImpl implements LoginService {

	@Autowired
	private UserDao userDao;

	@Override
	public AjaxObj updateLogin(String username, String password, HttpSession session) throws Exception {
		long count = userDao.countUsername(username);
		if (count <= 0) {
			return new AjaxObj(0, "该用户帐号不存在！");
		} else if (count > 1) {
			return new AjaxObj(0, "系统中存在多个【" + username + "】用户名，请联系管理员！");
		} else {
			User user = userDao.loadByUsername(username);
			if (user.getStatus() == -1) {
				return new AjaxObj(0, "该用户帐号被停用，请联系管理员！");
			}
			if (user.getPassword().equals(Md5Util.md5(username, password))) {
				return new AjaxObj(1, "登录成功！", user);
			} else {
				return new AjaxObj(0, "用户名或密码错误，请重新登录！");
			}
		}
	}

}
